package com.caiyouxi.pay.service.impl;

import com.caiyouxi.common.bean.QueryParams;
import com.caiyouxi.common.bean.ResData;
import com.caiyouxi.common.cache.RedisService;
import com.caiyouxi.common.service.BaseService;
import com.caiyouxi.pay.mapper.PaymentGatewayMapper;
import com.caiyouxi.pay.model.PaymentGateway;
import com.caiyouxi.pay.service.PaymentGatewayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class PaymentGatewayServiceImpl extends BaseService implements PaymentGatewayService {
    @Autowired
    private PaymentGatewayMapper mapper;
    @Autowired
    private RedisService redisService;

    @Override
    public ResData delete_payment(PaymentGateway bean) {
        return success(mapper.delete_payment(bean.getId()));
    }

    @Override
    public ResData insertSelective(PaymentGateway bean) {
        return success(mapper.insertSelective(bean));
    }

    @Override
    public ResData selectByPrimaryKey(PaymentGateway bean) {
        return success(mapper.selectByPrimaryKey(bean.getId()));
    }

    @Override
    public ResData updateByPrimaryKeySelective(PaymentGateway bean) {
        return success(mapper.updateByPrimaryKeySelective(bean));
    }

    @Override
    public ResData get_patment_list(PaymentGateway bean) {
        Integer pageList = Integer.parseInt(redisService.get("sys.pagesize").toString());
        QueryParams page_list = new QueryParams();
        if (bean.getPage_size() == 0){
            bean.setPage_size(pageList);
        }
        page_list.setPage_size(bean.getPage_size());
        page_list.setPage(bean.getPage());
        page_list.setList(mapper.get_patment_list(bean));
        page_list.setTotal(mapper.get_patment_count(bean));
        return success(page_list);
    }
}
